<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends MY_Controller {
	//构造函数
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Index Page for this controller.
	 */
	public function index()
	{
	    $data = array();
	    //获取三条最新的新闻
	    $data['recent_news'] = $this->home->get_rencent_news();
	    //获取前五条notice
	    $data['notices'] = $this->home->get_five_notice();

	    //获取lecture
	    $data['lectures'] = $this->home->get_five_lecture();

	    //获取老师信息
	    $data['advpeo'] = $this->db->select('pe_id,pe_name,pe_image,c_id')->from('people')->where('c_id',31)->get()->result_array();

		template('home/index',$data);
	}

	public function search()
	{
		$data = array();
		$words = $this->input->get('keys',TRUE);
		if(strlen($words) == 1)
		{
			$this->error('输入的关键字太少啦！');
		}
		if($words == '' || $words=='SEARCH NOW')
		{
		     $data['art_data'] = array();
		     $data['peo_data'] = array();
		}
		else
		{
	        //搜索文章中
	        $art_sql = "SELECT `aid`,`cid`,`title`,`desc`,`addtime` FROM `caup_article` WHERE `status` > 0 AND (`title` LIKE '%{$words}%' OR  `desc` LIKE '%{$words}%')  ORDER BY `updatetime` DESC, `sort` ASC;";
	        $data['art_data'] = $this->db->query($art_sql)->result_array();
	   		// p($data['art_data']);
	        //搜索人员
	        $peo_sql = "SELECT `pe_id`,`c_id`,`pe_name`,`pe_sec_title` FROM `caup_people` WHERE `pe_status` > 0 AND (`pe_name` LIKE '%{$words}%' OR  `pe_sec_title` LIKE '%{$words}%')  ORDER BY `pe_name` DESC, `pe_sort` ASC;";
	        $data['peo_data'] = $this->db->query($peo_sql)->result_array();
	        $data['words'] = $words;
			template('home/search',$data);
		}
	}
}